<template>
	<view>
		<view class="search">
			<search-bar @click="goSearch"></search-bar>
		</view>
		<!-- 轮播图 -->
		<swiper circular :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator :url="`/subpkg/goods-detail/goods-detail?goods_id=${item.goods_id}`">
					<image class="swiper-img" :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="item,index in navList" :key="index">
				<image :src="item.image_src" @click="goCate(index)"></image>
			</view>
		</view>
		<!-- 楼层 -->
		<view class="floor-list">
			<view class="floor-item" v-for="item,index in floorList" :key="index">
				<!-- 标题 -->
				<view class="floor-title">
					<image :src="item.floor_title.image_src" mode=""></image>
				</view>
				<!-- 内容 -->
				<view class="floor-content">
					<!-- 左 -->
					<view class="left">
						<image @click="goList(item.product_list[0])" mode="widthFix"
							:style="{width:item.product_list[0].image_width + 'rpx'}"
							:src="item.product_list[0].image_src"></image>

					</view>
					<!-- 右 -->
					<view class="right">
						<image @click="goList(e)" mode="widthFix" :style="{width:e.image_width + 'rpx'}" :key="i"
							v-for="e,i in item.product_list" v-if="i !== 0" :src="e.image_src"></image>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import tabBarMixins from '../../mixins/tabBarMixins.js'
	export default {
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: [],
				mixins: [tabBarMixins]
			};
		},
		onLoad() {
			this.getSwiperList(),
				this.getNavList(),
				this.getFloorList()
		},
		methods: {
			goSearch() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			},
			//跳转到商品列表
			goList(obj) {
				const param = obj.navigator_url.split('?')[1]
				uni.navigateTo({
					url: `/subpkg/goods-list/goods-list?${param}`
				})
			},
			// 获取楼层数据
			async getFloorList() {
				const {
					data: {
						message,
						meta
					}
				} = await uni.$http.get('/api/public/v1/home/floordata')
				//判断请求是否成功
				if (meta.status !== 200) return uni.$showMsg()
				this.floorList = message
			},
			//跳转到分类页面
			goCate(index) {
				if (index === 0) {
					//跳转
					//跳转到非tabBar页面
					//uni.navigateTo()
					//跳转到tabBar页面
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			// 获取导航方法
			async getNavList() {
				const {
					data: {
						message,
						meta
					}
				} = await uni.$http.get('/api/public/v1/home/catitems')
				//判断请求是否成功
				if (meta.status !== 200) return uni.$showMsg()
				this.navList = message
			},
			// 获取轮播图数据
			async getSwiperList() {
				const {
					data: {
						message,
						meta
					}
				} = await uni.$http.get('/api/public/v1/home/swiperdata')
				//判断请求是否成功
				if (meta.status !== 200) return uni.$showMsg()
				this.swiperList = message
			}
		}
	}
</script>

<style lang="scss">
	.search {
		position: sticky;
		left: 0;
		top: 0;
		right: 0;
		z-index: 999;
	}

	.swiper-img {
		width: 100%;
		height: 330rpx;
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 6px 0;

		.nav-item {
			width: 128rpx;
			height: 140rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.floor-title {
		image {
			width: 100%;
			height: 59rpx;
		}
	}

	.floor-content {
		display: flex;
		padding: 6px;

		.right {
			margin-left: 6px;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
		}
	}
</style>
